package com.alks.entity.data.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * <p>
 * 
 * </p>
 *
 * @author ms
 * @since 2023-08-17
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("PC_STITCH_DETAIL")
@ApiModel(value="PcStitchDetail对象", description="")
public class PcStitchDetail implements Serializable {

    private static final long serialVersionUID = 1L;

    private String companyId;

    @ApiModelProperty(value = "部门ID")
    private String deptNo;

    @ApiModelProperty(value = "部门名称")
    private String deptName;

    @ApiModelProperty(value = "I 入库 O 发料")
    private String slipType;

    @ApiModelProperty(value = "入库/发料 时间")
    private LocalDate slipDate;

    @ApiModelProperty(value = "指令")
    private String lotNo;

    @TableField(exist = false)
    @ApiModelProperty(value = "数量总")
    private Integer qty;

    @TableField(exist = false)
    @ApiModelProperty(value = "订单总")
    private Integer ordQty;

    @TableField(exist = false)
    @ApiModelProperty(value = "（没找到）厂区")
    private String factory;

    @TableField(exist = false)
    @ApiModelProperty(value = "颜色")
    private String color;

    @TableField(exist = false)
    @ApiModelProperty(value = "型体")
    private String style;

    @ApiModelProperty(value = "尺码数量")
    private Float qty1;

    private Float qty2;

    private Float qty3;

    private Float qty4;

    private Float qty5;

    private Float qty6;

    private Float qty7;

    private Float qty8;

    private Float qty9;

    private Float qty10;

    private Float qty11;

    private Float qty12;

    private Float qty13;

    private Float qty14;

    private Float qty15;

    private Float qty16;

    private Float qty17;

    private Float qty18;

    private Float qty19;

    private Float qty20;

    private Float qty21;

    private Float qty22;

    private Float qty23;

    private Float qty24;

    private Float qty25;

    private Float qty26;

    @ApiModelProperty(value = "创建时间")
    private LocalDateTime sysDate;

    @ApiModelProperty(value = "创建人")
    private String sysUser;

    private String cfmFlag;

    @ApiModelProperty(value = "订单号")
    private String slipNo;

    private String stkName;

    @ApiModelProperty(value = "备注")
    private String remark;

    private String stockArea;

    @ApiModelProperty(value = "0为内部部门  1为外发单位")
    private Integer outDept;

    @ApiModelProperty(value = "单据是否已打印 Y代表已打印")
    private String printFlag;

    @ApiModelProperty(value = "创建时间")
    private LocalDateTime updateDate;

    @ApiModelProperty(value = "创建人")
    private String updateUser;

    /*根据索引去更新对应qty的值*/
    public void updateQty(int index, int qty) {
        if (index < 1 || index > 26) {
            throw new IllegalArgumentException("无效索引: " + index);
        }
        float increment = qty;
        // 根据isAddition来决定是增加还是减少
//        int increment = isAddition ? qty : -qty;

        switch (index) {
            case 1:
                qty1 = qty1 != null ? qty1 + increment : increment;
                break;
            case 2:
                qty2 = qty2 != null ? qty2 + increment : increment;
                break;
            case 3:
                qty3 = qty3 != null ? qty3 + increment : increment;
                break;
            case 4:
                qty4 = qty4 != null ? qty4 + increment : increment;
                break;
            case 5:
                qty5 = qty5 != null ? qty5 + increment : increment;
                break;
            case 6:
                qty6 = qty6 != null ? qty6 + increment : increment;
                break;
            case 7:
                qty7 = qty7 != null ? qty7 + increment : increment;
                break;
            case 8:
                qty8 = qty8 != null ? qty8 + increment : increment;
                break;
            case 9:
                qty9 = qty9 != null ? qty9 + increment : increment;
                break;
            case 10:
                qty10 = qty10 != null ? qty10 + increment : increment;
                break;
            case 11:
                qty11 = qty11 != null ? qty11 + increment : increment;
                break;
            case 12:
                qty12 = qty12 != null ? qty12 + increment : increment;
                break;
            case 13:
                qty13 = qty13 != null ? qty13 + increment : increment;
                break;
            case 14:
                qty14 = qty14 != null ? qty14 + increment : increment;
                break;
            case 15:
                qty15 = qty15 != null ? qty15 + increment : increment;
                break;
            case 16:
                qty16 = qty16 != null ? qty16 + increment : increment;
                break;
            case 17:
                qty17 = qty17 != null ? qty17 + increment : increment;
                break;
            case 18:
                qty18 = qty18 != null ? qty18 + increment : increment;
                break;
            case 19:
                qty19 = qty19 != null ? qty19 + increment : increment;
                break;
            case 20:
                qty20 = qty20 != null ? qty20 + increment : increment;
                break;
            case 21:
                qty21 = qty21 != null ? qty21 + increment : increment;
                break;
            case 22:
                qty22 = qty22 != null ? qty22 + increment : increment;
                break;
            case 23:
                qty23 = qty23 != null ? qty23 + increment : increment;
                break;
            case 24:
                qty24 = qty24 != null ? qty24 + increment : increment;
                break;
            case 25:
                qty25 = qty25 != null ? qty25 + increment : increment;
                break;
            case 26:
                qty26 = qty26 != null ? qty26 + increment : increment;
                break;
            default:
                throw new IllegalStateException("无效索引: " + index);
        }
    }

    /*根据索引和传入的值刷新对应qty的值*/
    public void updateAllQty(int index, Float qty) {
        if (index < 1 || index > 26) {
            throw new IllegalArgumentException("无效索引: " + index);
        }

        String fieldName = "qty" + index;
        try {
            Field field = PcStitchDetail.class.getDeclaredField(fieldName);
            field.setAccessible(true);
            field.set(this, qty);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            throw new RuntimeException("更新字段时发生错误", e);
        }
    }

}
